﻿(function () {
	church.galleries =
		{
			settings: {
				urls: {
					refreshGrid: '',
					refreshPager: ''
				},
				vars: {
				},
				elements: {
					gridContent: '#content',
					pagerContent: '#pager'
				}
			},

			list: {
				init: function (settings) {
					$.extend(true, church.galleries.settings, settings);
					church.galleries.list.initGrid();
				},

				initGrid: function () {
					church.galleries.list.initPager();
				},

				initPager: function () {
					$(church.galleries.settings.elements.pagerContent).pager(function (page) {
						church.galleries.list.refresh(church.galleries.settings.elements.gridContent, church.galleries.settings.urls.refreshGrid, page);
						church.galleries.list.refresh(church.galleries.settings.elements.pagerContent, church.galleries.settings.urls.refreshPager, page);
					});
				},

				refresh: function (content, refreshUrl, pageNumber) {
					$(content).load(
						refreshUrl,
						{ pageNumber: pageNumber },
						function () { church.galleries.list.initGrid(); });
				}
			}
		};
})();